package com.example.madman.yuejian.Adapter;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.madman.yuejian.Bean.CourseBean;
import com.example.madman.yuejian.R;

import java.util.List;


public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private  List<CourseBean> list;
    private Context context;
    private LayoutInflater inflater;

    public ActivityListAdapter(Context context)
    {
        this.inflater = LayoutInflater.from(context);
        this.context=context;
    }

    public void setList(List<CourseBean> l){
        list=l;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = inflater.inflate(R.layout.fragment_activity,parent,false);
        RecyclerView.ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder( RecyclerView.ViewHolder holder, int position) {
        CourseBean bean = list.get(position);
        if(bean==null) return;
        final ViewHolder viewHolder= (ViewHolder) holder;
        viewHolder.text_course.setText(bean.getCourseinfo());
        viewHolder.image_course.setImageBitmap(BitmapFactory.decodeResource(
                context.getResources(), R.drawable.club));

        Glide.with(context)
                .load("http://192.168.155.1/yuejian/public/static/assets/img/"+bean.getCoursepic())
                . placeholder(R.drawable.club)
                .into(viewHolder.image_course);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    @Override
    public long getItemId(int position) {
        return position;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView text_course;
        ImageView image_course;

        public ViewHolder(View itemview) {
            super(itemview);

            text_course = (TextView) itemview.findViewById(R.id.text_course);
            image_course = (ImageView) itemview.findViewById(R.id.image_course);
        }


    }
}
